#include "UtilityPCH.h"
#include "UT_TimeLine.h"

using namespace Utility;

//----------------------------------------------------------------------------
//UT_TimeLine
//---------------------------------------------------
UT_TimeLine::UT_TimeLine()
	: m_eTimerState(TS_STOP)
	, m_fCurrentScaleTime(0.0f)
	, m_fDeltaScaleTime(0.0f)
	, m_fLastScaleTickTime(0.0f)
	, m_fCurrentRealTime(0.0f)
	, m_fDeltaRealTime(0.0f)
	, m_fLastRealTickTime(0.0f)
	, m_fPlaySpeed(1.0f)
	, m_dwBeginTimeInMS(0)
{
}
//---------------------------------------------------
UT_TimeLine::~UT_TimeLine()
{
}
//---------------------------------------------------
void UT_TimeLine::Tick()
{
	if(m_eTimerState != TS_START)
		return;

	m_fCurrentRealTime  = ((float)(timeGetTime() - m_dwBeginTimeInMS)) / 1000.0f;
	m_fDeltaRealTime    = (m_fCurrentRealTime - m_fLastRealTickTime);
	m_fLastRealTickTime = m_fCurrentRealTime;

	m_fDeltaScaleTime	= m_fDeltaRealTime * m_fPlaySpeed;
	m_fCurrentScaleTime = m_fLastScaleTickTime + m_fDeltaScaleTime;
	m_fLastScaleTickTime = m_fCurrentScaleTime;
}
//---------------------------------------------------
void UT_TimeLine::StartTimeLine()
{
	m_eTimerState = TS_START;
	m_dwBeginTimeInMS = timeGetTime();
}
//---------------------------------------------------
void UT_TimeLine::StopTimeLine()
{
	m_eTimerState = TS_STOP;
}
//---------------------------------------------------
void UT_TimeLine::PauseTimeLine()
{
	m_eTimerState		= TS_PAUSE;
	m_fDeltaRealTime	= 0.0f;
	m_fDeltaScaleTime	= 0.0f;
}
//---------------------------------------------------
void UT_TimeLine::PlayTimeLine()
{
	if(m_eTimerState != TS_PAUSE)
		return;

	m_eTimerState = TS_START;
}
//---------------------------------------------------
void UT_TimeLine::SetPlaySpeed(float fSpeed)
{
	m_fPlaySpeed = fSpeed;
}